import { useUser } from '@/stores/index.js'
import { createRouter, createWebHistory } from 'vue-router'
// import SonOne from '@/views/SonOne.vue'
// import SonTwo from '@/views/SonTwo.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // { path: '/sonone', component: SonOne },
    // { path: '/sontwo', component: SonTwo }
    {
      path: '/login',
      component: () => {
        return import('@/views/Login/LoginPage.vue')
      }
    },
    {
      path: '/',
      component: () => {
        return import('@/views/Manage/ManagePage.vue')
      },
      redirect: '/manage/arcticlemanage',
      children: [
        {
          path: '/manage/arcticleclassification',
          component: () => {
            return import('@/views/Manage/ArcticleManagement.vue')
          }
        },
        {
          path: '/manage/arcticlemanage',
          component: () => {
            return import('@/views/Manage/ArticleClassification.vue')
          }
        },
        {
          path: '/manage/basicinformation',
          component: () => {
            return import('@/views/Manage/BasicInformation.vue')
          }
        },
        {
          path: '/manage/changeimage',
          component: () => {
            return import('@/views/Manage/ChangeImage.vue')
          }
        },
        {
          path: '/manage/resetpassword',
          component: () => {
            return import('@/views/Manage/ResetPassword.vue')
          }
        }
      ]
    }
  ]
})

router.beforeEach((to) => {
  const User = useUser()
  //什么情况需要跳转到登陆页面，无非就是没有token并且又不是login页面
  if (!User.token && to.path !== '/login') {
    return '/login'
  }
})

export default router
